package com.yupi.yuoj.controller.test;

import cn.hutool.core.date.DateUtil;
import cn.hutool.json.JSONUtil;
import com.yupi.yuoj.common.BaseResponse;
import com.yupi.yuoj.common.ErrorCode;
import com.yupi.yuoj.common.ResultUtils;
import com.yupi.yuoj.exception.BusinessException;
import com.yupi.yuoj.exception.ThrowUtils;
import com.yupi.yuoj.model.dto.post.PostAddRequest;
import com.yupi.yuoj.model.entity.CompileInfo;
import com.yupi.yuoj.model.entity.Post;
import com.yupi.yuoj.model.entity.User;
import com.yupi.yuoj.service.UserService;
import com.yupi.yuoj.utils.EmailUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.BeanUtils;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.TimeUnit;

/**
 * @Description TODO
 * @Author JFeng
 * @Date 2024/3/3
 */

@RestController
@RequestMapping("/drone")
@Slf4j
public class DroneController {
    @Resource
    private EmailUtil emailUtil;

    @Resource
    private UserService userService;

    @RequestMapping("/get")
    public BaseResponse<Object> get() {
        log.info("/api/drone/get调用");
        User adminUser = userService.getById(1703772912254312450L);
        return ResultUtils.success(adminUser);
    }

    /**
     * 发送构建成功通知
     *
     * @return
     */
    @RequestMapping("/sendNotice")
    public BaseResponse<Object> sendNotice() {
//        , "996039876@qq.com", "3110311633@qq.com"
        CompileInfo compileInfo = CompileInfo.builder().message(htmlContent)
                .toEmailAddress(Arrays.asList("qzhujf1012@qq.com")).build();
        log.info("api/drone/sendNotice 接口调用。");
        return emailUtil.sendNormalEmail(compileInfo);
    }

    @RequestMapping("/sendCode/{mail}/{code}")
    public void sendCode(@PathVariable String mail, @PathVariable String code) {
        emailUtil.sendNormalEmail(mail, code);
    }

    public static String htmlContent = "<!DOCTYPE html>\n" +
            "<html lang=\"en\">\n" +
            "<head>\n" +
            "    <meta charset=\"UTF-8\">\n" +
            "    <meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\">\n" +
            "    <title>发版通知</title>\n" +
            "    <style>\n" +
            "        body {\n" +
            "            font-family: Arial, sans-serif;\n" +
            "            background-color: #f4f4f4;\n" +
            "            margin: 0;\n" +
            "            padding: 0;\n" +
            "            display: flex;\n" +
            "            justify-content: center;\n" +
            "            align-items: center;\n" +
            "            height: 100vh;\n" +
            "        }\n" +
            "        .card {\n" +
            "            background-color: #fff;\n" +
            "            border-radius: 10px;\n" +
            "            box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);\n" +
            "            padding: 20px;\n" +
            "            width: 300px;\n" +
            "            text-align: center;\n" +
            "        }\n" +
            "        h1 {\n" +
            "            color: #4CAF50;\n" +
            "        }\n" +
            "    </style>\n" +
            "</head>\n" +
            "<body>\n" +
            "    <div class=\"card\">\n" +
            "        <h1>发版成功！</h1>\n" +
            "        <p>您的应用已成功发布。</p>\n" +
            "        <p>" + DateUtil.now() + "</p>\n" +
            "    </div>\n" +
            "</body>\n" +
            "</html>";
}
